﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using AMPLibrary.Collections;
using AMPLibrary.Media;

namespace MediaLibrary.Controls
{
    /// <summary>
    /// Interaction logic for PlaylistSelectionWindow.xaml
    /// </summary>
    public partial class PlaylistSelectionWindow : Window
    {
        /// <summary>
        /// 
        /// </summary>
        public Playlist SelectedPlaylist
        {
            get;
            set;
        }

        /// <summary>
        /// 
        /// </summary>
        public PlaylistSelectionWindow()
        {
            InitializeComponent();
            SelectedPlaylist = null;
            BindPlaylists();
        }

        /// <summary>
        /// 
        /// </summary>
        private void BindPlaylists()
        {
            PlaylistCollection playlistCollection = PlaylistCollection.GetPlaylistCollection();
            playlistListBox.ItemsSource = playlistCollection;

            if (playlistListBox.Items.Count < 1)
            {
                playlistListBox.ItemsSource = null;
                playlistListBox.ItemsSource = "No playlists available";
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            this.Close();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void selectPlaylistButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Playlist playlist = (Playlist)playlistListBox.SelectedItem;

                if (playlist != null)
                {
                    SelectedPlaylist = playlist;
                    DialogResult = true;
                    this.Close();
                }
            }
            catch
            {
                DialogResult = false;
            }
        }
    }
}
